<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/boot.js"></script>
</head>

<body>
    <div class="layui-fluid">
        <div class="flexrow">
            <div class="layui-panel list-left-container" style="width: 200px;">
                <ul id="datatree" class="ztree"></ul>
            </div>
            <div class="layui-panel list-right-container">
                <div class="list-search-container">
                    <button class="layui-btn layui-btn-sm" onclick="HandleAdd()"><i class="layui-icon layui-icon-add-1 layui-font-12"></i>新增参数</button>
                    <div class="list-search-item">
                        <span>参数名称：</span>
                        <input id="config_name" autocomplete="off" class="layui-input">
                    </div>
                    <button class="layui-btn layui-btn-sm" style="margin-left:5px" onclick="BindData()"><i class="layui-icon layui-icon-search layui-font-12"></i>搜索</button>
                </div>
                <table class="layui-table" lay-data="{id: 'datagrid'}" lay-filter="datagrid">
                    <thead>
                        <tr>
                            <th lay-data="{field:'config_name',width:200}">参数名称</th>
                            <th lay-data="{field:'config_value',width:300}">参数值</th>
                            <th lay-data="{field:'remark'}">说明</th>
                            <th lay-data="{field:'sort_num',width:80,align:'center'}">排序</th>
                            <th lay-data="{fixed: 'right', width:175, align:'center', toolbar: '#op'}">操作</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</body>
<script type="text/html" id="op">
    <button class="layui-btn layui-btn-sm" lay-event="HandleEdit"><i class="layui-icon layui-icon-edit layui-font-12"></i>编辑</button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="HandleDelete"><i class="layui-icon layui-icon-delete layui-font-12"></i>删除</button>
</script>
<script>
    var group_id = "";

    $(function() {
        BindData();
    })

    function BindData() {
        BindTableData();
        BindTreeData();
    }

    function BindTableData() {
        var param = {
            config_name: $("#config_name").val(),
            group_id: group_id
        }
        BindTable("datagrid", "system/setting/config/list", param)
    }

    function TreeNodeClick(event, treeId, treeNode, clickFlag) {
        group_id = treeNode.id;
        BindTableData();
    }


    function BindTreeData() {
        BindTree("datatree", "system/setting/group/tree", { groupTag: "Config" }, TreeNodeClick);
    }

    function HandleAdd() {
        OpenDialog('新增参数', 'system/config/config_add.html?group_id=' + group_id, 800, 600, function() {
            BindData();
        })
    }

    function HandleEdit(RowData) {
        OpenDialog('修改参数', 'system/config/config_edit.html?row_id=' + RowData.row_id, 800, 600, function() {
            BindData();
        })
    }

    function HandleDelete(RowData) {
        OpenConfirm('确认删除？', function() {
            var param = {
                row_id: RowData.row_id
            }
            HttpPost(JSON.stringify(param), 'system/setting/config/delete', function(result) {
                if (result.code == 0) {
                    OpenSuccessMessage("删除成功")
                    BindData();
                } else {
                    OpenFail(result.msg);
                }
            })
        })
    }
</script>

</html>